<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/3/31
 * Time: 14:06
 */

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Request;
class Preferred extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function index()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $list = [];
        $list1 = Db::name('programme')->alias('a')->join('admin b','a.principal_id=b.id')->where('a.course_type_id',1)->field('a.id,a.title,a.image,a.look,a.likes,a.collect,b.nickname,b.avatar')->limit(4)->select();
        $list2 = Db::name('programme')->alias('a')->join('admin b','a.principal_id=b.id')->where('a.course_type_id',2)->field('a.id,a.title,a.image,a.look,a.likes,a.collect,b.nickname,b.avatar')->limit(4)->select();
        $list3 = Db::name('programme')->alias('a')->join('admin b','a.principal_id=b.id')->where('a.course_type_id',3)->field('a.id,a.title,a.image,a.look,a.likes,a.collect,b.nickname,b.avatar')->limit(4)->select();
        $list4 = Db::name('programme')->alias('a')->join('admin b','a.principal_id=b.id')->where('a.course_type_id',4)->field('a.id,a.title,a.image,a.look,a.likes,a.collect,b.nickname,b.avatar')->limit(4)->select();

        $list['铁血军事商学院'] = $list1;
        $list['忆群人团建'] = $list2;
        $list['前行问道户外'] = $list3;
        $list['华商北斗咨询'] = $list4;
        if(!$list)
            $this->error('暂无数据');
        $this->success('',$list);
    }
}